package com.cn.lf.wx.dacs.bussiness.author.action;

import java.io.Serializable;

import cn.hutool.http.HttpStatus;


public class Response implements Serializable {

	private static final long serialVersionUID = 1L;

	/**
	 * HttpStatus
	 */
	private static final Integer OK = HttpStatus.HTTP_OK;
	private static final Integer ERROR = HttpStatus.HTTP_INTERNAL_ERROR;

	private Object data;
	private Meta meta;

	private Response() {

	}

	public static Response success(String msg) {
		Response response = new Response();
		return response.setMeta(OK, msg);
	}

	public static Response success() {
		Response response = new Response();
		return response.setMeta(OK, "");
	}

	public static Response failure(String msg) {
		Response response = new Response();
		return response.setMeta(ERROR, msg);
	}

	public static Response failure() {
		Response response = new Response();
		return response.setMeta(ERROR, "");
	}

	public static Response result(Integer code, String msg) {
		Response response = new Response();
		return response.setMeta(code, msg);
	}

	public static Response result(Integer code) {
		Response response = new Response();
		return response.setMeta(code, "");
	}

	public static Response result(boolean bool) {
		Response response = new Response();
		return bool ? response.setMeta(OK, "") : response.setMeta(ERROR, "");
	}

	private Response setMeta(Integer code, String msg) {
		this.meta = new Meta(code, msg);
		return this;
	}

	public Response data(Object data) {
		this.data = data;
		return this;
	}

	public class Meta {

		private Integer code;
		private String msg;

		private Meta(Integer code, String msg) {
			this.code = code;
			this.msg = msg;
		}

		public Integer getCode() {
			return code;
		}

		public String getMsg() {
			return msg;
		}
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public Meta getMeta() {
		return meta;
	}

	public void setMeta(Meta meta) {
		this.meta = meta;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static Integer getOk() {
		return OK;
	}

	public static Integer getError() {
		return ERROR;
	}
	
	

}
